package chen.web.controller.forum.model;

import chen.web.forum.Category;
import chen.web.forum.CategoryManager;
import chen.web.forum.TopicPermission;
import chen.web.forum.TopicPermissionConfig;
import chen.web.user.PermissionConfigRepository;

public class Permission {

	private CategoryManager cm;

	Permission(CategoryManager cm){
		this.cm = cm;
	}
	
	public boolean canManage(Category category){
		TopicPermissionConfig config = PermissionConfigRepository.loadCurrent(TopicPermissionConfig.class);
		if((config.isDeleteSubject() || config.isCancelTop() || config.isSetDigest() || config.isSetTop() || config.isMoveSubject()) && topicPermission().inManagementCategorys(category)){
			return true;
		}
		return false;
	}
	
	private TopicPermission topicPermission;
	public TopicPermission topicPermission(){
		if(topicPermission == null){
			topicPermission = new TopicPermission(cm);
		}
		return topicPermission;
	}

}
